<template>
  <div>
    <el-tree ref="tree" node-key="id" :data="list" default-expand-all show-checkbox check-strictly :props="{label: 'name'}" />
    <el-row slot="footer" type="flex" justify="end">
      <el-button size="small">取消</el-button>
      <el-button size="small" type="primary" @click="hSubmit">确定</el-button>
    </el-row>
  </div>
</template>

<script>
import { getPermissionList } from '@/api/permisson'
import { inqRoles, assignPerm } from '@/api/setting'
import { transDataTreeData } from '@/utils'
export default {
  name: 'VueHrAssignPermission',
  props: {
    curId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      list: []
    }
  },
  created() {
    this.loadPermissionList()
  },
  methods: {
    async hSubmit() {
      const permIds = this.$refs.tree.getCheckedKeys()
      await assignPerm({ id: this.curId, permIds: permIds })
      this.$emit('success')
    },
    // 权限的渲染
    async loadPermissionList() {
      try {
        const res = await getPermissionList()
        this.list = transDataTreeData(res.data)
        const detail = await inqRoles(this.curId)
        this.$refs.tree.setCheckedKeys(detail.data.permIds)
        // console.log(detail, 'wwj')

        // console.log(res, 'wwj')
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
